package cz.cvut.fit.web.nakupniSeznam.ws.conv;

import java.net.URI;
import java.util.ArrayList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import cz.cvut.fit.web.nakupniSeznam.data.Category;

@XmlRootElement(name = "root")
public class CategoriesConverter extends AbstractConverter {

	public CategoriesConverter() {
		categories = new ArrayList<CategoryConverter>();

	}

	public CategoriesConverter(java.util.List<Category> input, URI uri) {
		super();
		categories = new ArrayList<CategoryConverter>();
		this.uri = resolveURI(uri);
		
		for (Category c : input) {
			this.categories.add(new CategoryConverter(c));
		}
	}

	private java.util.List<CategoryConverter> categories;

	@XmlElement(name = "category")
	@XmlElementWrapper
	public java.util.List<CategoryConverter> getCategories() { 
		return categories;
	}

	@Override
	protected URI resolveURI(URI uri) {
		String s = uri.getPath().replaceFirst("/categor.*", "/category/");
		URI listUri = URI.create(s);
		URI resolvedUri = uri.resolve(listUri);
		return resolvedUri;
	}
	
	@XmlElement
	public URI getUri() {
		return super.getUri();
	}

}
